package com.onlineMIS.ORM.entity.headQ.finance;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.onlineMIS.ORM.DAO.headQ.finance.FinanceCategoryImpl;
import com.onlineMIS.common.Common_util;
import com.onlineMIS.common.ExcelTemplate;
import com.onlineMIS.common.loggerLocal;

public class AllAccountsFlowTemplate extends ExcelTemplate {

	public static final DecimalFormat df = new DecimalFormat("#.00");

	private final int date_row_ind = 1;
	private final int data_row_ind = 4;

	private final int chain_column = 0;
	private final int sales_q_column = 1;

	private List<FinanceBillFlowDetailsVO> list = new ArrayList<FinanceBillFlowDetailsVO>();
	private Date startDate;
	private Date endDate;
	
	public AllAccountsFlowTemplate(Date startDate, Date endDate,  String templateWorkbookPath, List<FinanceBillFlowDetailsVO> list
			) throws IOException {
			super(templateWorkbookPath);
			this.startDate = startDate;
			this.endDate = endDate;
			this.list = list;
		}




	public HSSFWorkbook process() {

		HSSFSheet sheet = templateWorkbook.getSheetAt(0);

		// 写报表头信息
		String startDate = Common_util.dateFormat.format(this.startDate);
		String endDate = Common_util.dateFormat.format(this.endDate);

		Row headerRow2 = sheet.getRow(1);
		headerRow2.createCell(1).setCellValue(startDate);

		Row headerRow3 = sheet.getRow(2);
		headerRow3.createCell(1).setCellValue(endDate);

		for (int j = 0; j < list.size(); j++) {
			FinanceBillFlowDetailsVO item = list.get(j);
			Row row = sheet.createRow(j + data_row_ind);
			if (item.getFinanceCategoryName() != null) {
				row.createCell(0).setCellValue(item.getFinanceCategoryName());
			}			
			row.createCell(1).setCellValue(item.getFlowId());		
			row.createCell(2).setCellValue(item.getFlowName());
			row.createCell(3).setCellValue(item.getTransferType());
			row.createCell(4).setCellValue(item.getBillDateS()); // 单据时间
			row.createCell(5).setCellValue(Double.toString(item.getTotal())); // 金额
			row.createCell(6).setCellValue(Double.toString(item.getBorrowerAmount()));
			row.createCell(7).setCellValue(Double.toString(item.getLenderAmount()));
			row.createCell(8).setCellValue(Double.toString(item.getBalance()));
			row.createCell(9).setCellValue(item.getFlowType());
		}
		return templateWorkbook;
	}

}
